import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FrameProfesor extends javax.swing.JFrame {
	private JTextField TxtNombre;
	private JTextField TxtCedula;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JButton BTBorrar;
	private JPanel jPanel1;
	private JButton BTCancelar;
	private JButton BTIncluir;
	private JLabel jLabel1;
	private JTextField TxtTituloAcad;
	private JTextField TxtApellido;
    private Seccion sec;

	public FrameProfesor() {
		super();
		initGUI();
	}
	public FrameProfesor(Seccion sec) {
		super();
		this.sec = sec;
		initGUI();
	}
    ActionListener AccIncluir = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			IncluirProfersor();
		}
    };
	
    public void MostrarProfesor()
    {
    	if(this.sec.getProfReg())
    	{
    		Profesor p = this.sec.getProf();
    		this.TxtApellido.setText(p.getApellido());
    		this.TxtNombre.setText(p.getNombre());
    		this.TxtTituloAcad.setText(p.getTitulo_acam());
    		this.TxtCedula.setText(Long.toString(p.getCedula()));
    		
    	    this.BTIncluir.setEnabled(false);
    	    this.BTBorrar.setEnabled(false);
    	    this.BTCancelar.setEnabled(true);
    	}
    }
    
	public void IncluirProfersor()
	{
		try
		{
			if(this.TxtApellido.getText().equals("") || this.TxtNombre.getText().equals("")
			   || this.TxtCedula.getText().equals("") || this.TxtTituloAcad.getText().equals(""))
	    		JOptionPane.showMessageDialog(null,"Debe llenar todos los datos para poder inscribir al profesor", "Faltan Datos", JOptionPane.ERROR_MESSAGE);
	    	else
	    	{
	            sec.setProf((long)Integer.parseInt(TxtCedula.getText()),
	            TxtNombre.getText(),TxtApellido.getText(),TxtTituloAcad.getText());
	            sec.setProfReg(true);
	            JOptionPane.showMessageDialog(null,"El profesor fué incluido con éxito", "Operación Realizada", JOptionPane.INFORMATION_MESSAGE);
	            MostrarProfesor();
	    	}
		}
		catch(Exception e)
		{
		  	JOptionPane.showMessageDialog(null,"Ingrese datos validos", "Error", JOptionPane.ERROR_MESSAGE);
		  	Borrar();
		}
		
	}
	
	ActionListener Borrar = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			BTBorrar.setMnemonic(KeyEvent.VK_B);
			Borrar();
		}
    };
    
	public void Borrar()
	{
		TxtCedula.setText("");
		TxtNombre.setText("");
		TxtApellido.setText("");
		TxtTituloAcad.setText("");
	}

	ActionListener Cancelar = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			Cerrar();
		}
    };
	public void Cerrar()
	{
		this.dispose();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(Color.white);
			this.setName("Profesor");
			this.setTitle("Profesor");
			this.setFont(new java.awt.Font("Courier 10 Pitch",0,28));
			{
				jLabel5 = new JLabel();
				getContentPane().add(jLabel5);
				jLabel5.setText("Datos del Profesor");
				jLabel5.setBounds(103, 8, 241, 35);
				jLabel5.setFont(new java.awt.Font("Bitstream Charter",1,28));
			}
			{
				BTIncluir = new JButton();
				getContentPane().add(BTIncluir);
				BTIncluir.setText("Incluir");
				BTIncluir.setBounds(62, 255, 85, 28);
				BTIncluir.addActionListener(AccIncluir);

			}
			{
				BTCancelar = new JButton();
				getContentPane().add(BTCancelar);
				BTCancelar.setText("Salir");
				BTCancelar.setBounds(298, 255, 100, 28);
			    BTCancelar.addActionListener(Cancelar);
			}
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1);
				jPanel1.setBounds(34, 46, 389, 192);
				jPanel1.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
				jPanel1.setName("Datos del Profesor");
				jPanel1.setOpaque(false);
				jPanel1.setLayout(null);
				{
					jLabel1 = new JLabel();
					jPanel1.add(jLabel1);
					jLabel1.setText("Cedula");
					jLabel1.setBounds(56, 30, 66, 15);
					jLabel1.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					TxtCedula = new JTextField();
					jPanel1.add(TxtCedula);
					TxtCedula.setBounds(155, 24, 132, 22);
					TxtCedula.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				}
				{
					jLabel2 = new JLabel();
					jPanel1.add(jLabel2);
					jLabel2.setText("Nombre");
					jLabel2.setBounds(53, 68, 66, 15);
					jLabel2.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					TxtNombre = new JTextField();
					jPanel1.add(TxtNombre);
					TxtNombre.setBounds(155, 61, 132, 22);
					TxtNombre.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				}
				{
					jLabel3 = new JLabel();
					jPanel1.add(jLabel3);
					jLabel3.setText("Apellido");
					jLabel3.setBounds(53, 106, 66, 15);
					jLabel3.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					TxtApellido = new JTextField();
					jPanel1.add(TxtApellido);
					TxtApellido.setBounds(155, 99, 132, 22);
					TxtApellido.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				}
				{
					jLabel4 = new JLabel();
					jPanel1.add(jLabel4);
					jLabel4.setText("Titulo Academico");
					jLabel4.setBounds(19, 134, 130, 35);
					jLabel4.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					TxtTituloAcad = new JTextField();
					jPanel1.add(TxtTituloAcad);
					TxtTituloAcad.setBounds(155, 139, 132, 22);
					TxtTituloAcad.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				}
			}
			{
				BTBorrar = new JButton();
				getContentPane().add(BTBorrar);
				BTBorrar.setText("Borrar");
				BTBorrar.setBounds(185, 255, 84, 28);
				BTBorrar.addActionListener(Borrar);
			}
			pack();
			this.setSize(465, 338);
			MostrarProfesor();
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
